package pers.cz.controller;

import cn.hutool.core.date.DateUtil;
import pers.cz.mapper.TestPartitionMapper;
import pers.cz.model.TestPartition;
import pers.cz.pub.BeanHelper;
import pers.cz.pub.CpublicFunc;
import pers.cz.session.ContextHolder;
import pers.cz.sharindmerge.ShardingTableMerge;
import pers.cz.spring.SpringContextUtil;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: PostGirl-panent
 * @description: TestPartitionUtilController
 * @author: Cheng Zhi
 * @create: 2022-04-23 15:41
 **/
@RestController
@Order(value = 10)
@RequestMapping(path = "TestPartitionUtilController")
public class TestPartitionUtilController {

    @GetMapping(path = "/test1")
    public String test1() {

        Map<String, Object[]> map = new HashMap<String, Object[]>();
        Integer[] soNbr = new Integer[] {123456};
        map.put("SO_NBR", soNbr);
        //ContextHolder.getRequestContext().put("SO_NBR", i);
        TestPartition testPartition = new TestPartition();
        //testPartition.setUpdatedTime(DateUtil.date());
/*        BeanHelper beanHelper = SpringContextUtil.getBean(BeanHelper.class);
        CpublicFunc cpublicFunc  = new CpublicFunc(beanHelper);
        Long soNbrs = cpublicFunc.getSoNbr();
        testPartition.setSoNbr(Integer.valueOf(soNbrs + ""));
        testPartition.setCreatedTime(DateUtil.date());
        SpringContextUtil.getBean(TestPartitionMapper.class).insertSelective(testPartition);*/
        //ContextHolder.getRequestContext().clear();
        //SpringContextUtil.getBean(TestPartitionMapper.class).selectAll();
        Long start = System.currentTimeMillis();
        ShardingTableMerge shardingTableMerge = new ShardingTableMerge();
        shardingTableMerge.batchQuery("test_partition",TestPartitionMapper.class);
        Long end = System.currentTimeMillis();

        return "success:" + (end-start);
    }
}
